package io.wdb.modules.activity.wxapp.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.wdb.common.utils.UUIDGenerator;


import io.wdb.modules.activity.wxapp.dao.HdCardAttenderDao;
import io.wdb.modules.activity.wxapp.entity.HdCardAttenderEntity;
import io.wdb.modules.activity.wxapp.service.HdCardAttenderService;



@Service("hdCardAttenderService")
public class HdCardAttenderServiceImpl implements HdCardAttenderService {
	@Autowired
	private HdCardAttenderDao hdCardAttenderDao;
	
	@Override
	public HdCardAttenderEntity queryObject(String id){
		return hdCardAttenderDao.queryObject(id);
	}
	
	@Override
	public List<HdCardAttenderEntity> queryList(Map<String, Object> map){
		return hdCardAttenderDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return hdCardAttenderDao.queryTotal(map);
	}
	
	@Override
	public synchronized void save(HdCardAttenderEntity hdCardAttender){
			Map<String, Object> map = new HashMap<>();
			map.put("cardInitiatorId", hdCardAttender.getCardInitiatorId());
			map.put("userId", hdCardAttender.getUserId());
			synchronized (hdCardAttender.getUserId()) {
			List<HdCardAttenderEntity> entities = hdCardAttenderDao.queryList(map);
			if(entities == null || entities.isEmpty()) {
				hdCardAttender.setId(UUIDGenerator.getUUID());
				hdCardAttenderDao.save(hdCardAttender);
			}
		}
		
	}
	
	@Override
	public void update(HdCardAttenderEntity hdCardAttender){
		hdCardAttenderDao.update(hdCardAttender);
	}
	
	@Override
	public void delete(String id){
		hdCardAttenderDao.delete(id);
	}
	
	@Override
	public void deleteBatch(String[] ids){
		hdCardAttenderDao.deleteBatch(ids);
	}
	
}
